package com.demo.dao;

import com.demo.common.model.Airroute;
import com.demo.common.model.Flighttime;
import com.jfinal.kit.Kv;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;

import java.util.List;

public class FlightTimeDao {

    private Flighttime dao = new Flighttime().dao();

    public Page<Flighttime> paginate(int pageNumber, int pageSize) {
        return dao.paginate(pageNumber, pageSize, "select *", "from flighttime order by id asc");
    }

    public Page<Flighttime> paginate(int pageNumber, int pageSize, Kv cond) {
        SqlPara sqlPara = dao.getSqlPara("searchFlighttime", cond);
        return dao.paginate(pageNumber, pageSize, sqlPara);
    }

    public Flighttime findById(int id) {
        return dao.findById(id);
    }

    public Flighttime findByFlighttimeno(String id, String flighttimeno) {
        String sql = "select * from flighttime where flighttimeno='" + flighttimeno + "'";
        if (StrKit.notBlank(id)) {
            sql += " and id <>" + id;
        }
        return dao.findFirst(sql);
    }

    public void deleteById(int id) {
        dao.deleteById(id);
    }

    public List<Flighttime> findByVerify(){
        return dao.find("select id,flighttimeno from flighttime where verify=1");
    }
}
